$s = shift || '([])';

%s = (')' => '(', ']' => '[', '}' => '{');

for (split //, $s) 
{
    if (exists $s{$_})
    {
        $err = 1, last unless @s;
        $err = 1, last unless pop @s eq $s{$_};
    }
    else
    {
        push @s, $_;
    }
}

$err = 1 if @s;

print $err ? 'Bad' : 'Good', " string\n";
